package com.company;

import java.util.Random;
import java.util.Scanner;

public class GuessNumber {

    public static void main(String[] args) {
        System.out.println("欢迎来到猜数字游戏，请输入1-100的整数");
        Scanner mfy = new Scanner(System.in);
        String cl;

        do {
            int r = (int) (Math.random() * 100 + 1);
            int i = 7;

            while (i > 0) {
                int xy = mfy.nextInt();
                if (xy < r) {
                    System.out.println("猜小了,再试一次吧");
                } else if (xy > r) {
                    System.out.println("猜大了，再试一次吧");
                } else {
                    System.out.println("恭喜你猜对了");
                    break;
                }
                i = i - 1;
                System.out.println("你还有" + i + "次机会");
            }
            if (i <= 0) {
                System.out.println("你没有机会了");
            }
            System.out.println("还要再玩一次吗?(y/n)");
            cl = mfy.next();
        }while (cl.equalsIgnoreCase("y"));

    }
}

